package com.cw.part3.controller;

import com.cw.part3.model.Emp;
import com.cw.part3.service.EmpService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("/findAll")
    @ResponseBody
    public List<Emp> findAll() {
        return empService.findAll();
    }

    @RequestMapping("/findPage")
    public String findPage(Model model) {

        PageInfo<Emp> pageInfo =  empService.findPage(1, 30);
        for (Emp emp:pageInfo.getList()){
            System.out.println(emp);
        }
        model.addAttribute("empList",pageInfo.getList());

        return "emp-list";
    }
}
